<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2021/12/16
 * Time: 10:07
 */

include_once '../tools/DbTools.php';
include_once '../tools/common.php';
session_start();
$is_login = getLoginStatus();
if(!$is_login){
    echo '尚未登陆，<a href="../user/loginUi.php">请先登录</a>';
    die;
}else {
    if(empty($_POST['cardCheck'])){
        echo '未选择需要注销的银行卡，<a href="anotherCards.php">请重新选择</a>';
    }
    $userinfo = $_SESSION[$_COOKIE['Token']];
    $mainCard = $userinfo['CardId'];
    $has_err = false;
    DbTools::InitDb();
    for($i=0;$i<count($_POST['cardCheck']);$i++){
        $TempCardId = $_POST['cardCheck'][$i];
        $sql = "select CardMoney from bankcard where CardId = ".$TempCardId;
        $reuslt = DbTools::select($sql);
        $money = $result[0]['CardMoney'];
        transferMoney($TempCardId,$mainCard,$money,1);
        $sql = "update bankcard set CardState = -1 where CardId = ".$TempCardId;
        $result = DbTools::noSelect($sql);
        if(!$result['status']){
            echo '状态更改:'.$result['message'];
            $has_err = true;
            break;
        }
    }
    DbTools::close();
    if(!$has_err){
        echo '注销银行卡成功:<a href="anotherCards.php">继续注销</a>&nbsp;&nbsp;&nbsp;<a href="../user/userinfo.php">返回用户中心</a>';
    }
}